/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ar.edu.utn.frsf.ofa.javaee7.tp.ejemplo.ecompras.controller;

import ar.edu.utn.frsf.ofa.javaee7.tp.ejemplo.ecompras.dao.InsumoDAO;
import ar.edu.utn.frsf.ofa.javaee7.tp.ejemplo.ecompras.modelo.Insumo;
import java.io.Serializable;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
import javax.inject.Inject;
import javax.inject.Named;

/**
 *
 * @author Administrador
 */
@Named(value = "insumoCtrl")
@SessionScoped
public class InsumoController implements Serializable {

    @Inject
    InsumoDAO insumoDao;
    
    @Inject
    transient Logger miLogger;
    
    private Insumo insumo;

    private List<Insumo> listaInsumo;

    @PostConstruct
    public void init(){
        miLogger.log(Level.INFO," INICIO BEAN INSUMO CONTROLLER ");
        this.insumo = new Insumo();
    }
    
    /**
     * @return the insumo
     */
    public Insumo getInsumo() {
        return insumo;
    }

    /**
     * @param insumo the insumo to set
     */
    public void setInsumo(Insumo insumo) {
        this.insumo = insumo;
    }

    /**
     * @return the listaInsumio
     */
    public List<Insumo> getListaInsumo() {
        if (this.listaInsumo == null) {
            this.listaInsumo = this.insumoDao.buscarTodos();
        }
        return this.listaInsumo;
    }
    
    public String nuevo(){
        miLogger.log(Level.INFO," CREAR NUEVO INSUMO");
        this.insumo = new Insumo();
        return null;
    }

    public String guardar(){
        this.insumoDao.guardar(this.insumo);
        this.listaInsumo = this.insumoDao.buscarTodos();
        this.insumo = null;
        return null;
    }

    public String borrar(){
        this.insumoDao.borrar(this.insumo);
        this.listaInsumo = this.insumoDao.buscarTodos();
        this.insumo = null;
        return null;
    }

}
